﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace newsteadWebService
{
    /// <summary>
    /// Summary description for NewsteadService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class NewsteadService : System.Web.Services.WebService
    { 
        [WebMethod]
        public string CheckStaffID(string staffID)
        {
            //string staffIDStatus = "";
            using (var con = new SqlConnection("Data Source=INRI;Initial Catalog=newstead;Persist Security Info=True;User ID=sa;Password=123"))
            using (var cmd = new SqlCommand("select count(*) from g_user where username = '" + staffID + "'", con))
            {   
                con.Open();
                var result = (int)cmd.ExecuteScalar();

                if (result > 0)
                { 
                    return "staffExist"; 
                } 
                 return "StaffNotExist";  
            }

        }

        [WebMethod]
        public string CheckStaffPassWord(string StaffPassWord, string StaffID )
        { 
            using (var con = new SqlConnection("Data Source=INRI;Initial Catalog=newstead;Persist Security Info=True;User ID=sa;Password=123"))
            using (var cmd = new SqlCommand("select count(*) from g_user where username = '" + StaffID + "' and password = (select (CONVERT(BINARY(64)," + StaffPassWord + ",2)))", con))
            { 
                cmd.CommandType = CommandType.Text;
                con.Open();
                var result = (int)cmd.ExecuteScalar(); 
                if (result > 0)
                { 
                    return "PasswordCorrect"; 
                }
                return "PasswordIncorrect!";
            }

        } 
    }
}
